﻿package mortal.game.view.task.drama.operations
{
    import Message.DB.Tables.*;
    import com.gengine.global.*;
    import mortal.common.*;
    import mortal.game.manager.*;
    import mortal.game.view.task.drama.operations.npctalk.*;

    public class TaskDramaOpBlackScreenThenTips extends Object implements ITaskDramaStepCommand
    {
        private var _isInited:Boolean;
        private var _maskText:TaskDramaTalkMaskText;

        public function TaskDramaOpBlackScreenThenTips()
        {
            return;
        }// end function

        public function dispose() : void
        {
            if (this._maskText != null)
            {
                this._maskText.dispose();
            }
            return;
        }// end function

        public function call(param1:TTaskDrama, param2:Function = null) : void
        {
            var data:TaskDramaTalkData;
            var onEnd:Function;
            var config:* = param1;
            var callback:* = param2;
            onEnd = function () : void
            {
                if (_maskText.parent != null)
                {
                    _maskText.parent.removeChild(_maskText);
                }
                if (callback != null)
                {
                    callback.apply();
                }
                return;
            }// end function
            ;
            var tips:* = config.talkText;
            if (!this._isInited)
            {
                this.init();
                this._isInited = true;
            }
            data = this.getNpcTalkData(tips);
            this._maskText.x = (Global.stage.stageWidth - data.rowWidth) / 2;
            this._maskText.y = Global.stage.stageHeight / 2 - 50;
            LayerManager.highestLayer.addChild(this._maskText);
            this._maskText.show(data, onEnd);
            return;
        }// end function

        public function cancel(param1:TTaskDrama, param2:Function = null) : void
        {
            if (this._maskText.parent != null)
            {
                this._maskText.parent.removeChild(this._maskText);
            }
            if (param2 != null)
            {
                param2.apply();
            }
            return;
        }// end function

        private function getNpcTalkData(param1:String) : TaskDramaTalkData
        {
            var _loc_2:* = new TaskDramaTalkData();
            _loc_2.popupTime = 0;
            _loc_2.rowWidth = Math.min(Global.stage.stageWidth, 800);
            _loc_2.showTime = 600;
            _loc_2.speed = 10;
            _loc_2.talk = param1;
            _loc_2.talkFontLeading = 6;
            _loc_2.talkFontSize = 24;
            var _loc_3:* = DisplayUtil.getStringPixes(param1, _loc_2.talkFontSize) + 10;
            if (_loc_3 > 800)
            {
                _loc_3 = 800;
            }
            _loc_2.rowWidth = _loc_3;
            return _loc_2;
        }// end function

        private function init() : void
        {
            this._maskText = new TaskDramaTalkMaskText();
            return;
        }// end function

    }
}
